"""为测试注册功能，我们需要一千个手机号和密码。请设计一个函数产生指定数量的手机号和密码，该函数返回一个手机号和密码的字典列表。
要求，手机号和密码都不能重复，且密码必须包含大小写与下划线，可包含数字，长度不小于8，不大于16。
最终输出结果可能为
[{"phone",""13456782344", "passord": "Ss_12345678"},{"phone",""13956782354", "passord": "S7Gj45678"}]"""

import random
import string

phone_prefixes = ["133", "149", "153", "173", "177", "180", "181", "189", "190", "191", "193",
                  "199", "130", "131", "132", "145", "155", "156", "166", "167", "171", "175",
                  "176", "185", "186", "196", "134", "135", "136", "137", "138", "139", "144",
                  "147", "148", "150", "151", "152", "157", "158", "159", "172", "178", "182",
                  "183", "184", "187", "188", "195", "197", "198", "170", "174"]


def get_password():

    string_num = string.ascii_uppercase + string.digits + string.ascii_lowercase + "_"
    while True:

        string_psw = random.sample(string_num, random.randint(8, 16))
        # print(string_psw)

        if "_" not in string_psw:
            continue

        password = "".join(string_psw)
        return password


def get_phone(num):

    phone_dict = {}
    for i in range(num):

        phoneNum = random.choice(phone_prefixes) + "".join(random.choice("0123456789") for i in range(8))
        password = get_password()
        phone_dict[phoneNum] = password

        if phoneNum in phone_dict:
            continue

        elif password in phone_dict:
            continue

    return [{'phone': key, 'password': value} for key, value in phone_dict.items()]



print(get_phone(3))